<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<script type="text/javascript">
	function update(id) {
	   $("#role_edit_dialog").dialog({title:'角色更新'}).dialog('open').dialog('refresh','role/edit/'+id);
	}
	
	function setFunc(id) {
	   $("#role_edit_dialog").dialog({title:'设置权限',width:540,height:450}).dialog('open').dialog('refresh','role/setFuncUI/'+id);
	}
	
	function searchForm(){
		$('#role_main_list').datagrid("load",{"roleName":$("input[name='roleName']").val()});
	}

	$(function() {
		$('#role_main_list').datagrid(
		{
			url : 'role/getPage',
			idField : "id",
			pagination:true,
			columns : [ [
					{
						field : 'id',
						title : '编号',
						width : 100,
						checkbox : true
					},
					{
						field : 'roleName',
						title : '角色名称',
						width : 100
					},
					{
						field : 'roleCode',
						title : '角色编码',
						width : 100
					},
					{
						field : 'cz',
						title : '操作',
						width : 100,
						formatter : function(value, row, index) {
							return "<span  onclick='update(\""+value+"\")'>更新</span>&nbsp;"+
							              "<span  onclick='setFunc(\""+value+"\")'>设置权限</span>";
						}
					} ] ],

			toolbar : [
					{
						iconCls : 'icon-add',
						text : '新增角色',
						handler : function() {
							$("#role_edit_dialog").dialog('open').dialog('refresh','role/add');
						}
					},'-',{
						iconCls : 'icon-remove',
						text : '删除角色',
						handler : function() {
							var selects = $("#role_main_list").datagrid("getSelections");

							if (selects != null && selects.length > 0) {
								var ids = "";

								for ( var i = 0; i < selects.length; i++) {
									ids += selects[i].id + ",";
								}

								ids = ids.substring(0,ids.length - 1);
								$.messager.confirm("提示","您确定要删除该角色？",function(data) {
													if (data) {
														$.post("role/batchDelete",
																{ids : ids},function() {
																	$('#role_main_list').datagrid("reload");
																});
													}
												});
							}
						}
					} ],
			fitColumns : true
		});

	});
</script>

<div class="easyui-layout" data-options="fit:true">   
    <div data-options="region:'north'" style="height:35px;">
    	<div style="margin-top: 5px; margin-left:10px;">
    		<form method="post" id="searchForm">
	    		角色名：<input name="roleName"/>&nbsp;&nbsp;
	    		<a id="searchBtn" href="#" class="easyui-linkbutton" onclick="searchForm()" data-options="iconCls:'icon-search'">查询</a>
	    	</form>
    	</div>
    </div>   
    <div data-options="region:'center'">
    	<table id="role_main_list" data-options="fit:true"></table>
    </div>   
 </div>

<div id="role_edit_dialog" class="easyui-dialog" title="角色添加" style="width:300px;height:160px;"   
        data-options="iconCls:'icon-save',modal:true,closed:true">   
</div> 